#include<set>
#include<list>
#include<map>
using namespace std;

class stepwise_settings_t:public global_settings_t{
public:
  bool use_db;
  string db_host;
  string db_user;
  string db_pw;
  string db_db;
  string db_table;
  string pedfile;
  string snpfile;
  string genofile;
  string covariatedatafile;
  string covariateselectionfile;
  bool impute_missing;
  string penalty_type;
  string penalty_file;
};

struct ModelChange{
  int rsindex;
  int action; //-1,0,+1
  double logL;
  double score;
};

typedef map<string,float> region_t;

class Stepwise:public Analyzer{
public:
  //Stepwise(IO * io, stepwise_settings_t * settings);
  Stepwise();
  void init(const ptree & pt);
  ~Stepwise();
  void run();
private:
  covar_map_t cmap;
  plink_data_t data;
  IO * io;
  list<region_t> region_list;
  stepwise_settings_t * settings;
  uint max_rank;
  uint max_obs;
  void init();
  void initRegion(region_t r);
  void fitRegion(region_t r);

  int totalsnps;
  int totalcovs;
  string * snparr;
  string * covarr;
  bool * snp_in_model;
  float * expgeno;

  int totalobs;
  float * fulldesignMat;
  float * workingdesignMat;
  float * covarmat;
  //int fullrank;
  int currentrank;
  int * fullaff;
  bool testmodel(int flip_index, double & logL,bool verbose);
  float penalty(region_t region,string rs);
  double current_logL;

};
